package com.csea.tools.exception;

import com.csea.tools.enums.ResultEnum;
import com.csea.tools.vo.JsonResultVo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 捕获异常返回JsonResultVo
 *
 * @author Csea
 * @title
 * @date 2019/12/26 14:39
 */
@ControllerAdvice
public class RuntimeExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public JsonResultVo handler(RuntimeException e) {
        return JsonResultVo.failure(ResultEnum.ERROR, e.getMessage());
    }

    @ExceptionHandler(ResultException.class)
    @ResponseBody
    public JsonResultVo resultExceptionHandler(ResultException e) {
        return JsonResultVo.failure(ResultEnum.ERROR, e.getMessage());
    }
}
